package network.tcp;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author mubei
 * @date 2021/12/4
 * @description  服务器
 */
public class Server {
    public static void main(String[] args) throws Exception {
        // 一个地址
        ServerSocket serverSocket = new ServerSocket(9999);

        Socket socket = serverSocket.accept();
        InputStream inputStream = socket.getInputStream();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        int length = 0;
        byte bys[] = new byte[1024];

        while((length = inputStream.read(bys))!=-1){
            baos.write(bys,0,length);
        }
        System.out.println(baos.toString());

        socket.close();
        inputStream.close();
        baos.close();


    }
}
